﻿using OctoOS.UI;
using System.Web.UI;
using OctoOS;
using System;
using System.Web;

/// <summary>
/// Summary description for MainPageArticlePreview
/// </summary>
public class MainArticleUIPreview : Image48ObjectPreview
{
	MainPageArticlePreview _preview;
	Category[] _categories;

	public MainArticleUIPreview(MainPageArticlePreview preview, Category[] categories)
	{
		_preview = preview;
		_categories = categories;
		HeaderText = _preview.Title;
		ImageUrl = "/images/article.gif";
		HeaderUrl = Urls.GetArticle(preview.ID, false, false, preview.Title);
		Body = new Literal(preview.Preface);
	}

	protected override void RenderFooterContent(HtmlTextWriter writer)
	{
		string catString = string.Empty;
        for(int i = 0; i < _preview.CategoryIDs.Length; i++)
        {
            var categoryID = _preview.CategoryIDs[i];
            var currentCategory = AppUtil.GetCategory(_categories, categoryID);

            if(catString.Length > 0)
                catString += ",";

            catString += currentCategory.Title;
        }
		

		writer.Write("<span");
		writer.WriteAttribute("style", "color:black");
		writer.Write(">");
		writer.Write(Resources.Main.shared_Categories + ": " + HttpUtility.HtmlEncode(catString));
		writer.Write("</span><br/>");

		writer.Write("<span>");
		writer.Write(Resources.Main.shared_Published + " ");
		
		var t = new Time(_preview.PublishStartTime.ToLocalTime());
		t.RenderControl(writer);

		if(_preview.PublishStopTime != DateTime.MaxValue)
		{
			writer.Write("<br/>");
			writer.Write(Resources.Main.shared_PublishStops + " ");
			writer.Write(_preview.PublishStopTime.ToShortDateString());
		}

		writer.Write("</span>");
	}
}